﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DomainModel;
using Utils;
using WebUI.Utils;

namespace WebUI.Models
{
    public class ShotsViewModel: BaseViewModel
    {
        private int _numPerPage = 20;

        public ShotsViewModel(int page)
            : base(new { Page = page})
        { }

        public List<LatestShot> LatestShotList { get; set; }

        public int PreviousPage { get; set; }
        public int NextPage { get; set; }

        protected override void SetVarsWhichDependOnDynamicParams(dynamic dynParams)
        {
            int page = dynParams.Page;
            LatestShotList = DataUtils.GetList<LatestShot>(ConstUtils.SP_GetLatestShots, new { Page = page, NumPerPage = _numPerPage });

            foreach (var shot in LatestShotList)
            {
                shot["AvatarUrl"] = ImageUtils.GetAvatarRelativeUrl(AvatarType.IndAvatar, shot.IndID, AvatarSizeEnum.Avatar_16x16, shot.AvatarFileExtension);
                shot["ShotUrl"] = ImageUtils.GetShotRelativeUrl(shot.IndID, shot.ShotID, ShotSizeEnum.Shot_200x133, shot.FileExtension);
            }

            PreviousPage = CommonUtilities.GetPreviousPage(page);
            if (LatestShotList.Count == _numPerPage && page < 30)
            {
                NextPage = page + 1;
            }

        }
        
    }
}